﻿Imports System.Linq
Imports TNCDAL

Public Class CompanyController
    Private objRepository As New CompanyRepository

    Public Function SelectAllRecord() As IQueryable(Of tblCompany)
        Return objRepository.SelectAllRecord()

    End Function

    Public Function SelectRecordById(ByVal id As Integer) As tblCompany
        Return objRepository.SelectRecordById(id)
    End Function

    ''' <summary>
    ''' Lấy danh sách Company theo Name (Name là duy nhất)
    ''' </summary>
    ''' <param name="Name"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SelectRecordByName(ByVal Name As String) As tblCompany
        Return objRepository.SelectRecordByName(Name)
    End Function

    Public Sub Insert(ByVal obj As tblCompany)
        objRepository.Insert(obj)
    End Sub

    Public Sub Update(ByVal obj As tblCompany)
        objRepository.Update(obj)
    End Sub

    Public Function SelectCustom(ByVal strName As String) As IQueryable
        Dim query = SelectAllRecord()

        If strName <> "" Then
            query = query.Where(Function(p) p.Name.ToLower.Contains(strName.ToLower))
        End If

        query = query.OrderBy(Function(p) p.Name)
        Return query
    End Function
End Class
